import {Directive, HostListener, ElementRef, Input} from "@angular/core";
import {Platform} from 'ionic-angular';

@Directive({
    selector: 'ion-textarea[focusCursorIos]' // Attribute selector
})
export class FocusCursorIosDirective {
    @HostListener('focus', ['$event.target'])
    @Input('focusCursorIos') value: any;
    OnFocus(){
        this.setCursor();
    }
    constructor(private platform: Platform,private element:ElementRef) {

    }

    setCursor(){
        let ta = this.element.nativeElement.querySelector("textarea");
        if(this.platform.is('ios')){
            let val=this.value;
            this.value='';
            setTimeout(()=>{
                this.value=val;
                ta.click();
            },50)
        }
    }


}
